package com.liao.content.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.liao.base.model.PageParams;
import com.liao.base.model.PageResult;
import com.liao.content.mapper.MovieBaseMapper;
import com.liao.content.model.dto.MovieBaseDto;
import com.liao.content.model.po.MovieBase;
import com.liao.content.model.po.MovieCategory;
import com.liao.content.service.MovieBaseService;
import com.liao.content.service.MovieCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 电影基本表 前端控制器
 * </p>
 *
 * @author liao
 */
@Slf4j
@RestController
@RequestMapping("movieBase")
public class MovieBaseController {


    private final String DefalutMt="1-1";

    @Autowired
    private MovieBaseService  movieBaseService;

    @Autowired
    MovieCategoryService movieCategoryService;


    @Autowired
    private MovieBaseMapper movieBaseMapper;





//    查询热门数据接口

    @GetMapping("/hotlist")
    public PageResult<MovieBase> hotlist(){
        PageResult<MovieBase> movieBasePageResult = movieBaseService.queryMovieBaseList(new PageParams(1, 10));
        return movieBasePageResult;

    }


    @GetMapping("/list")
    public List<MovieBase> list(@RequestParam(value = "mt", required = false) String mt){
        LambdaQueryWrapper<MovieBase> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        if (mt == null){
            mt=DefalutMt;
        }
        List<MovieBase> movieBases = movieBaseMapper.selectList(lambdaQueryWrapper.eq(MovieBase::getMt, mt));
        return movieBases;

    }


    @GetMapping("/bystlist")
    public MovieBaseDto bystlist(@RequestParam(value = "st", required = false) String st){
        LambdaQueryWrapper<MovieBase> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        if (st == null){
            st=DefalutMt;
        }


        List<MovieBase> movieBases = movieBaseMapper.selectList(lambdaQueryWrapper.eq(MovieBase::getSt, st));
        MovieBaseDto movieBaseDto=new MovieBaseDto();

        LambdaQueryWrapper<MovieCategory> info = new LambdaQueryWrapper<MovieCategory>().eq(MovieCategory::getId, st);
        MovieCategory one = movieCategoryService.getOne(info);

        BeanUtils.copyProperties(one,movieBaseDto);
        movieBaseDto.setInfo(movieBases);
        return movieBaseDto;

    }


    @GetMapping("/detail/{id}")
    public MovieBase detail(@PathVariable("id") Integer id){


        MovieBase movieBase = movieBaseMapper.selectById(id);
        return movieBase;

    }


}
